<template>
  <div>
    <div>
      <label class="label">员工查询：</label>
      <el-input v-model="name" placeholder="请输入姓名" style="width: 15%;"></el-input>
      <el-button type="primary" icon="el-icon-search" style="margin-left: 15%" @click="getSortPage">搜索</el-button>
    </div>

    <div>
      <el-table :data="record" stripe style="width: 100%">
        <el-table-column align="center" prop="name" label="姓名" width="180"></el-table-column>

        <!-- 性别列 -->
        <el-table-column align="center" prop="gender" label="性别" width="300">
          <template v-slot="scope">
            <span v-if="scope.row.gender === '男'">男</span>
            <span v-else-if="scope.row.gender === '女'">女</span>
            <span v-else>未知</span>
          </template>
        </el-table-column>

        <!-- 年龄列 -->
        <el-table-column align="center" prop="age" label="年龄" width="100"></el-table-column>

        <!-- 电话列 -->
        <el-table-column align="center" prop="phone" label="电话" width="300"></el-table-column>

        <!-- 家庭住址列 -->
        <el-table-column align="center" prop="address" label="家庭住址" width="300"></el-table-column>

        <!-- 在岗状态列 -->
        <el-table-column align="center" label="在岗状态" width="120">
          <template v-slot="scope">
            <span v-if="scope.row.status === 1">在岗</span>
            <span v-else-if="scope.row.status === 2">已接单未结束</span>
            <span v-if="scope.row.status === 0">休息中</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { getSortPage } from '../api/employee'

export default {
  data() {
    return {
      name: '',
      currentPage: 1,
      pageSize: 5,
      total: 0,
      record: [],  // 员工记录
    };
  },
  created() {
    this.getSortPage();
  },
  methods: {
    // 获取员工信息
    getSortPage() {
      let param = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        name: this.name, // 搜索条件
      };
      getSortPage(param)
        .then(res => {
          if (res.data.code === 1) {
            let allRecords = res.data.data.records;
            if (this.name) {
              // 进行模糊匹配
              this.record = allRecords.filter(item => item.name.includes(this.name));
            } else {
              // 没有搜索条件时显示所有记录
              this.record = allRecords;
            }
            this.total = this.record.length;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    
    // 调度算法：根据员工状态和需求进行资源调度
    dispatchResources() {
      // 例子：简单根据状态判断是否可调度
      const availableStaff = this.record.filter(person => person.status === 1);  // 筛选在岗人员

      if (availableStaff.length > 0) {
        availableStaff.forEach(person => {
          console.log(`分配人员：${person.name}`);
          // 可以添加实际的分配逻辑
        });
      } else {
        console.log('没有可用的员工进行调度');
      }
    }
  }
}
</script>

<style>
/* 可以根据需要自定义样式 */
</style>
